package com.jj.service;

import com.jj.entity.menu;
import com.jj.entity.userlogin;
import com.jj.mapper.MenuMapper;
import com.jj.mapper.userMapper;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class userserviceimpl implements userservice {

    @Resource
    private userMapper userMapper;
    @Resource
    private MenuMapper menuMapper;
    @Resource
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public boolean login(userlogin us) {
        userlogin ul = userMapper.lo(us.getLogin_name());
        if (ul != null){
            if (us.getLogin_paw().equals(ul.getLogin_paw())){
               //登录成功
                redisTemplate.setKeySerializer(new StringRedisSerializer());
                //查询用户的所有权限菜单
                List<menu> userMenus = menuMapper.getMenuByUserId(ul.getUser_id());
                //放入Redis中
                redisTemplate.delete("se");
                redisTemplate.opsForValue().get("se");
                redisTemplate.opsForValue().set("se",userMenus);
                return true;
            }
        }
        return false;
    }

    @Override
    public List<userlogin> selectAll() {
        List<userlogin> userlogins = userMapper.selectAll();
        return userlogins;
    }

    @Override
    public int inserttj(userlogin ul) {
        int inserttj = userMapper.inserttj(ul);
        return inserttj;
    }

    @Override
    public int deletesc(int user_id) {
        return userMapper.deletesc(user_id);
    }

    @Override
    public int updatexg(userlogin un) {
        return userMapper.updatexg(un);
    }

    @Override
    public userlogin lo(String us) {
        return userMapper.lo(us);
    }

//    @Override
//    public List<user0> getmy() {
//        return userMapper.getmy();
//    }
//
//    @Override
//    public List<user0> getmy1() {
//        return userMapper.getmy1();
//    }
//
//    @Override
//    public List<user0> getmy2() {
//        return userMapper.getmy2();
//    }
}
